package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/6/28 16:52
 * @since v1.0
 */
@Getter
public enum CustomerWastageEnum {
    WIN("1", "enum.customerWastage.name.win", "win"),


    UN_ACCEPT("2", "enum.customerWastage.name.un_accept", "unAccept"),


    AGREE("3", "enum.customerWastage.name.agree", "agree"),


    INCONFORMITY("4", "enum.customerWastage.name.inconformity", "inconformity"),


    OTHER("5", "enum.customerWastage.name.other", "other"),
    ;


    private String code;
    private String name;
    private String attr;

    CustomerWastageEnum(String code, String name, String attr) {
        this.code = code;
        this.name = name;
        this.attr = attr;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 根据code获取对应枚举
     *
     * @return RelativeProductEnum
     */
    public static CustomerWastageEnum getByCode(String code) {
        if (code == null) {
            return OTHER;
        }
        for (CustomerWastageEnum cache : values()) {
            if (Objects.equals(cache.getCode(), code) ) {
                return cache;
            }
        }
        return OTHER;
    }
}
